//
//  ZHDrawLineView.m
//  Doctor
//
//  Created by liuzhishan on 15/12/16.
//  Copyright © 2015年 shanshan. All rights reserved.
//

#import "ZHDrawLineView.h"
#import "ZHClinicAllData.h"
#define LINEWIGHT  1.5

@interface ZHDrawLineView ()

@property (nonatomic,assign) BOOL isOver;

@end

@implementation ZHDrawLineView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        
    }
    return self;
}

-(void)setDataWithArray:(NSMutableArray *)array andIndex:(NSInteger)index
{
    self.isOver = NO;
    self.dataArray = array;
    self.index = index;
    
    if (array.count - 1 == index) {
        
        self.isOver = YES;
    }
    
    [self setNeedsDisplay];
    
}

-(void)drawRect:(CGRect)rect
{
    
    if (self.isOver) return;
       
    CGContextRef  context = UIGraphicsGetCurrentContext();
    
    
    CGContextSetLineWidth(context, LINEWIGHT);
    

    float x =  0;
    
    
    ZHClinicAllData *model = [self.dataArray objectAtIndex:self.index];
    
    float y = [ZHLineGetHigh getHightWithModel:model andIndex:0];
    
    CGContextMoveToPoint(context,x,y);
    
    
    model = [self.dataArray objectAtIndex:(self.index + 1)];
    
    y = [ZHLineGetHigh getHightWithModel:model andIndex:0];

    x = WIDPro  * 78;
    
    CGContextAddLineToPoint(context, x, y);
    
    CGContextSetStrokeColorWithColor(context, BLUECOLOR.CGColor);
    
    CGContextStrokePath(context);
    
    
    
    CGContextSetLineWidth(context, LINEWIGHT);
      x =  0;
    
    model = [self.dataArray objectAtIndex:self.index];
    
     y = [ZHLineGetHigh getHightWithModel:model andIndex:1];
    
    CGContextMoveToPoint(context,x,y);
  
   
    model = [self.dataArray objectAtIndex:(self.index + 1)];
    
    
    y = [ZHLineGetHigh getHightWithModel:model andIndex:1];

    
    
    x = WIDPro  * 78;
    
    CGContextAddLineToPoint(context, x, y);
    
     CGContextSetStrokeColorWithColor(context, ORANGECOLOR.CGColor);
    
    
    CGContextStrokePath(context);

}

@end
